package com.web.portal.utils.template;

import com.web.portal.utils.CodeUtils;

import java.util.Random;

public class TemplateCode {

    public TemplateCode() {
    }

    public static String getNumCode(int n) {
        return CodeUtils.getSmsCode(n);
    }

//    public static Object[] getImageCode() {
//        return VerificationCodeUtil.createImage();
//    }

    public static String getOrderCode(int n, String projectName) {
        String orderCode = CodeUtils.getOrderCode(n);
        if (projectName != null) {
            orderCode = orderCode + projectName;
        }

        return orderCode;
    }

    public static String getCapitalEnglishCode(Integer n) {
        String str = "";

        for(int i = 0; i < n; ++i) {
            str = str + (char)((int)(Math.random() * 26.0D + 97.0D));
        }

        return str;
    }

    public static String getLowerEnglishCode(Integer n) {
        String str = "";

        for(int i = 0; i < n; ++i) {
            str = str + (char)((int)(Math.random() * 26.0D + 97.0D));
        }

        return str;
    }

    public static String getEnglishCode(Integer n) {
        String str = "";

        for(int i = 0; i < n; ++i) {
            Random r = new Random();
            boolean flag = r.nextBoolean();
            if (flag) {
                str = str + (char)((int)(Math.random() * 26.0D + 97.0D));
            } else {
                str = str + (char)((int)(Math.random() * 26.0D + 65.0D));
            }
        }

        return str;
    }
}
